package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"user_srv/model"
	"user_srv/proto"
)

type Server struct {
	proto.UnimplementedUserServer
}

// 用户注册
func (s *Server) UserRegister(ctx context.Context, in *proto.UserRegisterRequest) (*proto.UserRegisterResponse, error) {
	u := model.User{
		Mobile:   in.Mobile,
		Password: in.Password,
	}
	register, err := u.Register()
	if err != nil {
		return nil, status.Error(codes.Internal, "用户注册失败")
	}
	return &proto.UserRegisterResponse{
		Id:       int64(register.ID),
		Mobile:   register.Mobile,
		Password: register.Password,
		NickName: register.NickName,
		Sex:      int64(register.Sex),
		Age:      int64(register.Age),
	}, nil
}
